#include "RenzoMustHave.h"
#include "RenzoVertexBuffer.h"
#include "RenzoRenderSystemGL.h"
#include "RenzoVertexBufferGL.h"
#include "RenzoRenderBufferGL.h"
#include "RenzoDisplayGL.h"

namespace Renzo
{
RenderSystemGL::RenderSystemGL(void)
{
	

	// GLUT
	int argc; char** argv;
	Renzoderer::instance()->getArguments(&argc, &argv);
	if (argc > 0)
		glutInit(&argc, argv);
	else {
		argc = 1;
		char* tmpArgv = "Renzoderer";
		glutInit(&argc, &tmpArgv);
	}
	//glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE );
	glutInitDisplayMode ( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
	glutInitWindowSize( Renzoderer::instance()->getWindowWidth(), Renzoderer::instance()->getWindowHeight() );
	glutCreateWindow( "" );

	// GLEW
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
	  /* Problem: glewInit failed, something is seriously wrong. */
	  fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
	}
	fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));



	// 
	// Create display and buffers
	// (should init in this order)
	//
	disp = new DisplayGL;
	rbuf = new RenderBufferGL;
	vbuf = new VertexBufferGL;
	
}

RenderSystemGL::~RenderSystemGL(void)
{
	rzDel(vbuf);
	rzDel(rbuf);
	rzDel(disp);
	
}

const char* RenderSystemGL::getName() {
	return RENDER_SYSTEM_NAME;
}
}
